package com.hjj.homieMatching.config;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Component
public class HttpSessionFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) {}

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        // 确保为每个请求创建会话，即使不直接使用session变量
        // 这对于WebSocket等需要依赖HttpSession的功能很重要
        req.getSession();
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {}
}
